package com.mimiwang.animal.service.Imp;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mimiwang.animal.mapper.AnimalPictureMapper;
import com.mimiwang.animal.service.IAnimalPictureService;
import com.mimiwang.animal.vo.AnimalPictureVo;
import com.mimiwang.common.vo.school.PageConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @AUTHOR:游李滨
 * @DATE:2023/4/19 15:56
 */

@Service
public class AnimalPictureServiceImpl implements IAnimalPictureService {
    @Autowired
    AnimalPictureMapper animalPictureMapper;

    @Override
    public PageInfo<AnimalPictureVo> selectPictureListByAnimalId(long animalId, PageConfig pageConfig) {
        PageHelper.startPage(pageConfig);
        List<Date> dates = animalPictureMapper.selectPictureCreatTimeListByAnimalId(animalId);
        PageHelper.startPage(new PageConfig());

        ArrayList<AnimalPictureVo> apList = new ArrayList<AnimalPictureVo>();
        for (Date date : dates) {
            AnimalPictureVo animalPictureVo = new AnimalPictureVo();
            animalPictureVo.setDate(date);
            animalPictureVo.setPictureList(animalPictureMapper.selectPictureListByCreatTime(animalId,date));
            apList.add(animalPictureVo);
        }
        return new PageInfo<>(apList);
    }
}
